// 发布时间
export const toDate = dateValue => {
  let dateTime = new Date(dateValue).getTime() / 1000
  if (dateTime === null) {
    return ''
  }
  let date = new Date(parseInt(dateTime) * 1000)
  let now = new Date().getTime()
  let second = Math.floor((now - date) / 1000)
  let minute = Math.floor(second / 60)
  let hour = Math.floor(minute / 60)
  let day = Math.floor(hour / 24)
  let month = Math.floor(day / 31)
  let year = Math.floor(month / 12)
  let Year = date.getFullYear()
  let ny = new Date().getFullYear()
  let oy = date.getFullYear()
  let Moth =
    date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1
  let Day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()
  if (oy < ny) {
    let y = (oy + '').substring(2, 4)
    return `${y}-${Moth}-${Day}`
  } else if (day > 0) {
    return `${Moth}-${Day}`
  } else if (hour > 0) {
    return hour + '小时前'
  } else if (minute > 0) {
    return minute + '分钟前'
  } else if (second > 0) {
    return second + '秒前'
  } else {
    return '刚刚'
  }
}

export const numValue = num => {
  let n = ''
  if (num >= 11000 && num <= 1000000) {
    n = Math.floor(num / 1000) / 10
    return `${n}万`
  } else if (num >= 1000000) {
    n = Math.floor(num / 1000) / 10
    return `${n}万+`
  } else {
    return num
  }
}

export const getDate = dateVal => {
  let dateTime = new Date(dateVal).getTime() / 1000
  let date = new Date(parseInt(dateTime) * 1000)
  let Moth =
    date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1
  let Day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()
  let hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours()
  let minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes()
  let ny = new Date().getFullYear()
  let oy = date.getFullYear()
  let y = (oy + '').substring(2, 4)
  if (oy < ny) {
    return `${y}-${Moth}-${Day} ${hour}:${minute}`
  } else {
    return `${Moth}-${Day} ${hour}:${minute}`
  }
}
